home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr53 / pctv4n_1.zip / WRAPTEST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-10  |  2KB  |  59 lines

  1. program WrapTest;
  2.  
  3. uses DBWrap;
  4.  
  5. var
  6.    RC                : integer;    {holds return codes from engine}
  7.    EBEngine          : TEBEngine;
  8.    db                : PEBDatabase;
  9.    view              : PEBView;
  10.    Entry_Date        : PEBField;   {we'll use this field a lot}
  11.  
  12.    F                 : text;
  13.    EDate, XNum, Desc : string;
  14.    Add, Update       : boolean;
  15.    ed, date          : longint;
  16.  
  17. begin
  18.    EBEngine.Init;
  19.    db   := EBEngine.OpenDatabase('XDATA');
  20.    View := db^.View('trans',                     {table}
  21.       'entry_date,x_number,description',         {fields}
  22.       'main');                                   {index}
  23.    Entry_Date := View^.Field('entry_date');
  24.  
  25.    assign(F, 'XACTIONS.TXT');   {file of transactions shown in mag}
  26.    reset(F);
  27.    repeat
  28.       readln(F, EDate);         {Conversion errors will be caught}
  29.       readln(F, XNum);          {by the object, whereas non-OOP }
  30.       readln(F, Desc);          {app assumed everything was OK.}
  31.  
  32.       Entry_Date^.Store(EDate);     {Magic: store as a string into}
  33.       ed := Entry_Date^.AsInteger;  {date field & retrieve as long}
  34.  
  35.       Add := false; Update := false;
  36.       rc := View^.Search(XNum);
  37.  
  38.       If RC = -1 then Add := true {record doesn't exist, so add it}
  39.       else If RC = 0 then         {record exists; should we update?}
  40.       begin
  41.          Date := Entry_date^.AsInteger;
  42.          If date <= ed then Update := true;
  43.          end;
  44.  
  45.       If Add or Update then            {Store everything at once}
  46.       begin
  47.          View^.Store(EDate+ParseChar+XNum+ParseChar+Desc);
  48.          If Add then View^.Add
  49.          else View^.Update;
  50.          end;
  51.  
  52.       until(eof(F));              {No more transactions to process}
  53.  
  54.    Dispose(View, Done);
  55.    Dispose(db, Done);
  56.  
  57.    writeln('Process Completed. No errors.');
  58. end.
  59.